#include<iostream>
typedef struct //基类
{
    void(*print)(void*);
}Base;


typedef struct //派生类A
{
    Base base;
    int a;

}DerivedA;

typedef struct //派生类B
{
    Base base;
    int b;
}DerivedB;

void printA(void *obj)//派生类A的print函数
{
    DerivedA* a = (DerivedA*)obj;
    printf("DerivedA:%d\n",a->a);
}
void printB(void *obj)//派生类B的print函数
{
    DerivedB* b = (DerivedB*)obj;
    printf("DerivedB:%d\n",b->b);
}
int main()
{
    DerivedA a  = {printA,10};//将printA和DerivedA结构体中base对象中的print函数指针绑定
    DerivedB b = {printB,20};
    Base* base_arry[2] = {&a.base,&b.base};
    for(int i = 0;i< 2;++i)
    {
        base_arry[i]->print((void*)base_arry[i]);
    }
    return 0;
}